home *** CD-ROM | disk | FTP | other *** search
- /*
- ### Execute an external executable and pipe the output to the proper winow ###
- */
-
- #include <stdio.h>
- #include <suntool/sunview.h>
- #include <suntool/textsw.h>
- #include <suntool/panel.h>
- #include <sunwindow/notify.h>
-
- int childpid,fromchild,tochild;
- FILE *fp_fromchild,*fp_tochild;
-
- void exec_panel_go_proc()
- {
- static Notify_value exec_pipe_reader(),exec_dead_child();
-
- int i;
- extern int save_option;
- extern char string[],lstring[],exec_dir_name[],exec_file_name[],exec_input_name[];
- extern Textsw exec_textsw;
- extern Panel_item exec_panel_go_item;
-
- all_reset();
-
- if(save_option==0){
- system_mess_proc(1,"Change the save option to either 2-D data or Full data.");
- return;
- }
-
- sprintf(string,"%s/%s",exec_dir_name,exec_input_name);
- textsw_store_file(exec_textsw,string,0,0);
- sprintf(string,"%s/%s < %s/%s",exec_dir_name,exec_file_name,exec_dir_name,exec_input_name);
-
- (void) decode_input_string(lstring,string);
- printf("%s\n",lstring);
- (void) pipe_create(lstring,&childpid,&fromchild,&tochild);
-
- /* Register input and wait3 functions to the notifier */
- (void) notify_set_input_func(exec_panel_go_item,exec_pipe_reader,fromchild);
- (void) notify_set_wait3_func(exec_panel_go_item,exec_dead_child,childpid);
- }
- /*
- ### Read the input pending on the pipe ###
- */
-
- static Notify_value exec_pipe_reader(item,fd)
- Panel_item item;
- int fd;
- {
- int i,result,save_option_old,lock_interval_old;
- extern int save_option,region_index,lock_interval;
- extern int aux_max;
- extern int *aux_on,*aux_win_mode;
- extern char exec_file_name[],error_mess[],error_yes[],error_no[];
- extern FILE *fp_fromchild;
-
- lock_interval_old = lock_interval;
- lock_interval = 0;
- if(region_index==2){
- /* aux_win_i runs from 0 to aux_max-1 */
- /* Count the number of open auxiliary windows */
- for(i=0;i<aux_max;i++){
- if(!aux_on[i]){
- /* Turn on aux_win_mode of chosed aux window */
- aux_win_mode[i]=1;
-
- /* Create_aux_window turns on aux_on */
- (void) create_aux_windows(i);
-
- /* Load data from a file pointer fp_fromchild
- This does the displaying and recording, too. */
- load_data(fp_fromchild);
-
- /* Refresh the panel items of aux panel */
- all_refresh();
- return(NOTIFY_DONE);
- }
- }
- /* All the auxiliary windows are used up. Take over one. */
- for(i=0;i<aux_max;i++){
-
- if(i==0){
- sprintf(error_mess,"No more aux windows. Take over aux_win[%d]?",i);
- sprintf(error_yes,"Confirm");
- if(i != aux_max-1){
- sprintf(error_no,"No. Move to next aux_win[%d]",i+1);
- }
- else {
- sprintf(error_no,"");
- }
- }
- else if(i<aux_max-1){
- sprintf(error_mess,"How about this aux_win[%d]?",i);
- sprintf(error_yes,"Confirm");
- sprintf(error_no,"Nope. Next!");
- }
- else {
- sprintf(error_mess,"This is the last chance. Do you want get aux_win[i]?",i);
- sprintf(error_yes,"Confirm");
- sprintf(error_no,"Cancel. Exit!");
- }
- result = (int) error_mess_proc(error_mess,error_yes,error_no);
- if(result){
- /* Turn on aux_win_mode of chosed aux window */
- aux_win_mode[i]=1;
- (void) destroy_aux_windows(i);
- /* Create_aux_window turns on aux_on */
- (void) create_aux_windows(i);
-
- /* Load data from a file pointer fp_fromchild
- This does the displaying and recording, too. */
- load_data(fp_fromchild);
-
- /* Refresh the panel items of aux panel */
- all_refresh();
- return(NOTIFY_DONE);
- }
- }
- }
- else {
- /* Load_data may change the save option */
- save_option_old = save_option;
- load_data(fp_fromchild);
- all_refresh();
- save_option = save_option_old;
- }
- lock_interval = lock_interval_old;
- return(NOTIFY_DONE);
- }
- /*
- ### Close the pipe and let the notifier know if the child process died ###
- */
-
- static Notify_value exec_dead_child(item,pid,status,rusage)
- Panel_item item;
- int pid;
- union wait *status;
- struct rusage *rusage;
- {
- extern int fromchild;
- (void) notify_set_input_func(item,NOTIFY_FUNC_NULL,fromchild);
- close(fromchild);
- return(NOTIFY_DONE);
- }
-